package com.yjzx.util.common.util.batch.merging;

import com.yjzx.util.common.util.BeanUtils.BaseInterface;

import java.util.function.Function;

/**
 * @author yjzx
 * @date 2024/8/27
 * @description DataMergingBuilder<T,U,R>
 */
public final class DataMergingBuilder<T,U extends Comparable<U>,R> {
    /**
     * 返回值类型
     */
    BaseInterface<R> reference;
    /**
     * 执行方法参数
     */
    T param;
    /**
     * 指定的节点
     */
    U u;
    /**
     * 节点的前一个值
     */
    U uPreceding;
    /**
     * 节点前执行的方法
     */
    Function<T, R> oldReportParam;
    /**
     * 节点后执行的方法
     */
    Function<T, R> newReportParam;

    private DataMergingBuilder() {
    }

    public static <T,U extends Comparable<U>,R>DataMergingBuilder<T,U,R> aDataMerging() {
        return new DataMergingBuilder<>();
    }
    /**
     * 返回值类型
     */
    public DataMergingBuilder<T,U,R> reference(BaseInterface<R> reference) {
        this.reference = reference;
        return this;
    }
    /**
     * 执行方法参数
     */
    public DataMergingBuilder<T,U,R> param(T param) {
        this.param = param;
        return this;
    }
    /**
     * 指定的节点
     */
    public DataMergingBuilder<T,U,R> u(U u) {
        this.u = u;
        return this;
    }
    /**
     * 节点的前一个值
     */
    public DataMergingBuilder<T,U,R> uPreceding(U uPreceding) {
        this.uPreceding = uPreceding;
        return this;
    }
    /**
     * 节点前执行的方法
     */
    public DataMergingBuilder<T,U,R> oldReportParam(Function<T, R> oldReportParam) {
        this.oldReportParam = oldReportParam;
        return this;
    }
    /**
     * 节点后执行的方法
     */
    public DataMergingBuilder<T,U,R> newReportParam(Function<T, R> newReportParam) {
        this.newReportParam = newReportParam;
        return this;
    }

    public DataMerging<T,U,R> build() {
        return new DataMerging<>(reference, param, u, uPreceding, oldReportParam, newReportParam);
    }
    public OverviewMergingBuilder<T,U,R> overviewBuild() {
        return new OverviewMergingBuilder<>(build());
    }
}
